package org.inspiration.dudu.common.exception;

import org.inspiration.dudu.common.constant.Constant;
import org.inspiration.dudu.common.pojo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result<Void> handleServiceException(ServiceException ue) {
        return Result.failure(ue.getCode(), ue.getMessage());
    }



    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result<Void> handleException(Exception e) {
        return Result.failure(Constant.SYSTEM_UNKNOWN_EXCEPTION + ": " + e.getMessage());
    }
}
